import Vue from 'vue'
import Vuex from 'vuex'
import db from '@/utils/db'
Vue.use(Vuex)
export default new Vuex.Store({
  state: {
    XFabricJson: db.get('XFABRICJSON', ''),
    XWatermarkType: Number(db.get('XWATERMARKTYPE', -1)), // 1 主图  2 长图  3 3:4  
    // XWatermarkType: 2, // 水印type 1 主图  2 长图  3 3:4  
    XShopItems: db.get('XSHOPITEMS', []),
  },
  mutations: {
    setFabricJson (state, val) {
      db.save('XFABRICJSON', val)
      state.XFabricJson = val
    },
    setWatermarkType (state, val) {
      db.save('XWATERMARKTYPE', val)
      state.XWatermarkType = val
    },
    setShopItems (state, val) {
      db.save('XSHOPITEMS', val)
      state.XShopItems = val
    },
  },
  getters: {
    GCanvasSize: state => {
      const { XWatermarkType } = state
      switch (XWatermarkType) {
        case 1: // 主图 800*800
          return { W: 800, H: 800, wL: 500, hL: 500, scaleL: 1.6, scaleS: 0.3, wS: 150, hS: 150, scaleLoad: 0.625 }
        case 2: // 长图 800*1200
          return { W: 800, H: 1200, wL: 500, hL: 750, scaleL: 1.6, scaleS: 0.3, wS: 150, hS: 225, scaleLoad: 0.625 }
        case 3: // 3:4 750 * 1000
          return { W: 750, H: 1000, wL: 500, hL: 667, scaleL: 1.5, scaleS: 0.3, wS: 150, hS: 200, scaleLoad: 0.6667 }
        default:
          return { W: 500, H: 500, wL: 500, hL: 500, scaleL: 1, scaleS: 0.3, wS: 150, hS: 150, scaleLoad: 1 }
      }
    }
  }
})
